using System;
using System.Text;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace WebAClient.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class Ids4Controller : ControllerBase
    {
     
        [AllowAnonymous]
        [HttpGet(nameof(IndexCodeToken))]
        public IActionResult IndexCodeToken()
        {
            Console.WriteLine($"{nameof(Ids4Controller)} -  {nameof(IndexCodeToken)} 端口号:" + HttpContext.Request.Host.Port);
            //http://localhost:5002/Ids4/IndexCodeToken?code=LcdShzTmJY55MtsyM2DnY7dnbXjGXgdU7J-az2p8w_0&scope=api1
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("{");
            foreach (var key in Request.Query.Keys)
            {
                sb.AppendLine($"\"{key}\":\"{Request.Query[key].ToString()}\",");
            }
            sb.AppendLine("\"site:\":\"WebAClient\""); //主要目的: 为了让json格式 是正确的

            sb.AppendLine("}");
            var txt = sb.ToString();
            return new ContentResult { Content = txt, ContentType = "application/json" };
        }
    }
}
